<!-- PDF预览弹窗 -->
<template>
  <div class="modal" :class="visible ? 'show' : 'hide'">
    <div class="toolbar">
      <button
        title="Close (Esc)"
        class="close"
        @click="$emit('update:visible', false)"
      ></button>
    </div>
    <div v-if="visible" style="width: 100%; height: 100%; position: relative">
      <iframe :src="url" width="100%" height="100%" frameborder="0" />
      <div class="imgWatermark">
        <div
          class="mark"
          v-for="(item, index) in 100"
          :key="index"
          :style="watermark.styles"
        >
          {{ watermark.text }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "preview-pdf",
  props: {
    url: {
      type: String,
      default: ""
    },
    watermark: {
      type: [Object, undefined],
      default: () => ({ text: "", styles: {} })
    },
    visible: {
      type: Boolean,
      default: false
    }
  }
};
</script>

<style lang="scss" scoped>
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  background-color: rgba(0, 0, 0, 0.3);
  transition: transform 0.6s;
}
.modal.show {
  transform: scale(1);
}
.modal.hide {
  transform: scale(0);
}
.imgWatermark {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 74px;
  left: 0;
  overflow: hidden;
  pointer-events: none;
}
.imgWatermark .mark {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 200px;
  height: 200px;
  transform: rotate(-30deg);
  color: rgba(180, 180, 180, 0.3);
  font-size: 16px;
}
.toolbar {
  background: rgba(0, 0, 0, 0.3);
  width: 100%;
  height: 44px;
  text-align: right;
}
.close {
  cursor: pointer;
  background: url()
    0 0 no-repeat;
  background-size: 264px 88px;
  width: 44px;
  height: 44px;
  background-position: 0 -44px;
  border: 0;
}
</style>
